{% extends 'cms/cms_base.html' %}
{% from "common/_macros.html" import static %}

{% block title %}用例执行结果{% endblock %}

{% block head %}
    <script src="{{ static("cms/js/querySparrow.js") }}"></script>
    <script src="{{ static("cms/js/caseExcuteRes.js") }}"></script>
    <style>
        table {
            border-spacing: 0;
            border-collapse: collapse;
            text-align: left;
        }
        /*关键设置 tbody出现滚动条*/
        table tbody {
            display: block;
            height: 430px;
            overflow-y: scroll;
        }
        table thead,
        tbody tr {
            display: table;
            width: 100%;
            table-layout: fixed;
        }
        /*关键设置：滚动条默认宽度是16px 将thead的宽度减16px*/
        table thead {
            width: calc( 100% - 16px);
        }
        table thead th {
            background: #ccc;
        }
    </style>
{% endblock %}

{% block page_title %}查询3小时内所有用例计划最新一个轮次的执行结果（共 {{ total }} 条数据）{% endblock %}

{% block main_content %}
    <div class="top-box-runRes" style="float: right; padding-bottom: 5px;">
        <span>用例名称：<input type="text" id="query_case_name" name="query_case_name" style="width: 200px;"></span>
        <span>所属计划：</span>
        <select id="query_plan" style="width: 200px;">
        <option value="0">请选择</option>
            {% for plan in planDict %}
                <option value="{{ plan }}">{{ planDict[plan][0] }}</option>
            {% endfor %}
        </select>
        <span>执行结果：</span>
        <select id="query_res_status" style="width: 80px;">
        <option value="0">请选择</option>
        <option value="1">成功</option>
        <option value="2">失败</option>
        <option value="3">未执行</option>
        </select>
        <button type="button" class="btn btn-warning" id="refresh-btn" onclick="queryCaseRunRes()">查询</button>
        <a href="/piecharts/" target="_blank">查看统计图</a>
    </div>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>用例名称</th>
                <th style="width: 80px;">执行结果</th>
                <th style="width: 90px;">http响应码</th>
                <th style="width: 150px;">执行时间</th>
                <th style="width: 90px;">执行方式</th>
                <th style="width: 150px;">所属计划</th>
                <th style="width: 80px;">耗时(ms)</th>
                <th style="width: 70px;">操作</th>
            </tr>
        </thead>
        <tbody>
            {% for item in res %}
                {% if item[12] == 1 %}
                    {% set runType = '自动执行' %}
                {% elif item[12] == 2 %}
                    {% set runType = '手动执行' %}
                {% elif item[12] == 3 %}
                    {% set runType = '调试用例' %}
                {% else %}
                    {% set runType = '未知' %}
                {% endif %}

                {% if item[7] == 1 %}
                    {% set res_status = '成功' %}
                {% elif item[7] == 9 %}
                    {% set res_status = '失败' %}
                {% else %}
                    {% set res_status = '未执行' %}
                {% endif %}

                {% set planName = planDict[item[18]][0] %}
                {% set planIsDel = planDict[item[18]][1] %}

                <tr data-res_id="{{ item[0] }}" data-wheel_no="{{ item[1] }}"  data-res_case_name="{{ casesDict[item[2]] }}"
                    data-res_case_path="{{ item[5] }}" data-res_case_parm="{{ item[6] }}" data-res_status="{{ res_status }}"
                    data-res_http_code="{{ item[8] }}" data-expect_res="{{ item[9] }}" data-res_detail="{{ item[10] }}"
                    data-cost_time="{{ item[11] }}" data-run_type="{{ runType }}" data-create_at="{{ item[15] }}"
                    data-res_case_sign="{{ item[3] }}" data-res_plan="{{ planName }}" data-plan_isDel="{{ planIsDel }}"
                    data-res_header="{{ item[17] }}">

                <td>
                    <a href="/case_manage?caseid={{ item[2] }}" target="_blank">{{ casesDict[item[2]] }}</a>
                </td>

                <td style="width: 80px;">
                    {% if res_status == '成功' %}
                        <span style="color: green;">成功</span>
                    {% elif res_status == '失败' %}
                        <span style="color: red;">失败</span>
                    {% else %}
                        <span style="color: #999999;">未执行</span>
                    {% endif %}
                </td>

                <td style="width: 90px;">
                    {% set httpcode = item[8] %}
                    {% if httpcode == 200 %}
                        <span style="color: green;">{{ httpcode }}</span>
                    {% else %}
                        <span style="color: red;">{{ httpcode }}</span>
                    {% endif %}
                </td>

                <td style="width: 150px;">{{ item[15] }}</td>
                <td style="width: 90px;">{{ runType }}</td>
                <td style="width: 150px;">
                    {% if planIsDel == 1 %}
                        <span style="color: #9b9fb1">{{ planName }}<span style="color: #FF8C00; font-size: smaller;">【已删除】</span></span>
                    {% else %}
                        <span>{{ planName }}</span>
                    {% endif %}
                </td>

                <td style="width: 80px;">
                    {% set costTime = item[11] %}
                    {% if costTime < 5000 %}
                        <span>{{ costTime }}</span>
                    {% elif costTime < 10000 %}
                        <span style="color: orange;">{{ costTime }}</span>
                    {% else %}
                        <span style="color: red;">{{ costTime }}</span>
                    {% endif %}
                </td>

                <td style="width: 70px;">
                    <button class="btn btn-default btn-xs preview-res-btn">详情</button>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <span>{{ pagination.links }}</span>

    <!-- 查看详细信息 -->
    <div class="modal fade" id="preview-res-dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">用例执行结果</h4>
                </div>
                <div class="modal-body">
                    <form action="" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用例名称：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-res_case_name" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">断言结果：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="preview-res_status" disabled="disabled">
                            </div>
                            <label class="col-sm-3 control-label">http响应码：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="preview-res_http_code" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">预期结果：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-expect_res" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">响应信息：</label>
                            <div class="col-sm-9">
                                <textarea type="text" class="form-control" name="preview-res_detail" disabled="disabled"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用例耗时：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="preview-cost_time" disabled="disabled">
                            </div>
                            <label class="col-sm-3 control-label">执行方式：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="preview-run_type" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请求URL：</label>
                            <div class="col-sm-9">
                                <textarea type="text" class="form-control" name="preview-res_case_path" disabled="disabled"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请求参数：</label>
                            <div class="col-sm-9">
                                <textarea type="text" class="form-control" name="preview-res_case_param"  disabled="disabled"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">headers：</label>
                            <div class="col-sm-9">
                                <textarea type="text" class="form-control" name="preview-res_header" disabled="disabled"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用例编号：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-res_case_sign" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属计划：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-res_plan" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">执行时间：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-create_at" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">轮次编码：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-wheel_no" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">result_id：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="preview-res_id" disabled="disabled">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="location.reload();">关闭</button>
                </div>
            </div>
        </div>
    </div>

{% endblock %}